#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, k;
ll a[N];
void solve() {
  cin >> n >> k;
  rep(i, 1, n) cin >> a[i];
  if (k == 1) {
    ll ans = a[1] + a[n];
    if (n > 2) {
      ll mx = *max_element(a + 2, a + n);
      ans = max(ans, mx + max(a[1], a[n]));
    }
    cout << ans << endl;
  } else {
    sort(a + 1, a + n + 1);
    ll sum = accumulate(a + n - k, a + n + 1, 0ll);
    cout << sum << endl;
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}